import Vue, { VueConstructor, PluginObject } from 'vue';
import axios from 'axios';

const instance = axios.create({
  withCredentials: true,
  maxRedirects: 0,
});

const Plugin: PluginObject<any> = {
  install: (v: VueConstructor) => {
    v.$axios = instance;
  },
};
Plugin.install = (v: VueConstructor) => {
  v.$axios = instance;
  window.axios = instance;
  Object.defineProperties(v.prototype, {
    $axios: {
      get() {
        return instance;
      },
    },
  });
};

Vue.use(Plugin);

export default Plugin;
